#include "../../mqServer/mq_binding.hpp"
#include <gtest/gtest.h>

using namespace mq;

mq::BindingManager::manager_ptr bd;

class BindingTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        cout << "所有单元测试前执行环境初始化" << endl;
        bd = make_shared<BindingManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        cout << "所有单元测试后执行环境清理" << endl;
        // bd->clear();
    }
};

TEST(binding_test, bind_test)
{
    bd->Bind("e1", "q1", "abc", true);
    bd->Bind("e1", "q2", "abdsf", true);
    bd->Bind("e1", "q3", "absdc", true);
    bd->Bind("e2", "q3", "absdc", true);
    bd->Bind("e3", "q4", "absdfc", false);
    bd->Bind("e5", "q3", "abdsfc", true);
}
TEST(binding_test, recovery_test)
{
    // ASSERT_EQ(bd->size(), 5);
    ASSERT_EQ(bd->exist_test("e1", "q1"), true);
    ASSERT_EQ(bd->exist_test("e1", "q2"), true);
    ASSERT_EQ(bd->exist_test("e1", "q3"), true);
    ASSERT_EQ(bd->exist_test("e2", "q3"), true);
    ASSERT_EQ(bd->exist_test("e5", "q3"), true);
    // ASSERT_EQ(bd->exist_test("e3", "q4"), false);
}
// TEST(binding_test, get_ex_binds_test)
// {
//     const MsgQueueBindingMap &qbmap = bd->getExchangeBindings("e1");
//     for (auto &it : qbmap)
//     {
//         b_ptr bind = it.second;
//         cout << bind->_ename << "|" << bind->_qname << "|" << bind->_binding_key << endl;
//     }
// }

// TEST(binding_test, unbind_test)
// {
//     // bd->unBind("e2", "q1");
//     bd->removeMsgQueueBindings("q3");
//     ASSERT_EQ(bd->size(), 2);
//     const MsgQueueBindingMap &qbmap = bd->getExchangeBindings("e1");
//     ASSERT_EQ(qbmap.size(), 2);
// }

// TEST(binding_test, get_one_binds_test)
// {
//     b_ptr bind = bd->getBinding("e5", "q3");
//     ASSERT_NE(bind, b_ptr());
//     ASSERT_EQ(bind->_binding_key, string("abdsfc"));
// }

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new BindingTest);
    RUN_ALL_TESTS();
    return 0;
}